import { Label } from "cc"
import { UITransform } from "cc"
import { _decorator, Component, Node } from "cc"
import { GlobalData } from "../GlobalData"
const { ccclass, property } = _decorator

@ccclass("UIEndingHpItem")
export class UIEndingHpItem extends Component {
  @property(UITransform)
  uITransformDPS: UITransform = null

  @property(UITransform)
  uITransformTank: UITransform = null

  @property(Label)
  labDPS: Label = null

  @property(Label)
  labTank: Label = null

  start() {}

  update(deltaTime: number) {}

  private index: number = 0
  init(index: number) {
    this.index = index

    let allDPS: number = 0
    for (let key in GlobalData.instance.arrRoleDamage) {
      allDPS += GlobalData.instance.arrRoleDamage[key]
    }

    let allTank: number = 0
    for (let key in GlobalData.instance.arrRoleBeDamage) {
      allTank += GlobalData.instance.arrRoleBeDamage[key]
    }

    const numDPS = Math.round((GlobalData.instance.arrRoleDamage[index] / allDPS) * 10000) / 100
    const numTank = Math.round((GlobalData.instance.arrRoleBeDamage[index] / allTank) * 10000) / 100

    this.labDPS.string = numDPS + "%"
    this.labTank.string = numTank + "%"

    this.uITransformDPS.width *= numDPS / 100
    this.uITransformTank.width *= numTank / 100
  }
}
